/*
 * 微信公众平台(JAVA) SDK
 *
 * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
 *
 * http://www.weixin4j.org/sdk/
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.mc.adapter.wechat.mpAPI.pay;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一下单
 *
 * 接口文档：http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1
 *
 * <b>应用场景</b>
 *
 * 除被扫支付场景以外，商户系统先调用该接口在微信支付服务后台生成预支付交易单，返回正确的预支付交易回话标识后再按扫码、JSAPI、APP等不同场景生成交易串调起支付。
 *
 * <b>是否需要证书</b>
 *
 * 不需要
 *
 * @author qsyang
 * @version 1.0
 */
public class UnifiedOrder {

	private String	appid;				// 公众账号ID 是
	private String	mch_id;				// 商户号 是
	private String	nonce_str;			// 随机字符串 是
	private String	sign;				// 签名 是
	private String	body;				// 商品描述 是
	private String	out_trade_no;		// 商户订单号 是
	private String	total_fee;			// 总金额 是
	private String	spbill_create_ip;	// 终端IP 是
	private String	notify_url;			// 通知地址 是
	private String	trade_type;			// 交易类型 是 取值如下：JSAPI，NATIVE，APP
	private String	openid;				// 用户标识

	public Map<String, String> toMap() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("appid", this.appid);
		map.put("body", this.body);
		map.put("mch_id", this.mch_id);
		map.put("nonce_str", this.nonce_str);
		map.put("notify_url", this.notify_url);
		map.put("openid", this.openid);
		map.put("out_trade_no", this.out_trade_no);
		map.put("spbill_create_ip", this.spbill_create_ip);
		map.put("total_fee", this.total_fee);
		map.put("trade_type", this.trade_type);
		return map;
	}

	public String toXML() {
		StringBuilder sb = new StringBuilder();
		sb.append("<xml>");
		sb.append("<appid><![CDATA[").append(this.appid).append("]]></appid>");
		sb.append("<body><![CDATA[").append(this.body).append("]]></body>");
		sb.append("<mch_id><![CDATA[").append(this.mch_id).append("]]></mch_id>");
		sb.append("<nonce_str><![CDATA[").append(this.nonce_str).append("]]></nonce_str>");
		sb.append("<notify_url><![CDATA[").append(this.notify_url).append("]]></notify_url>");
		sb.append("<openid><![CDATA[").append(this.openid).append("]]></openid>");
		sb.append("<out_trade_no><![CDATA[").append(this.out_trade_no).append("]]></out_trade_no>");
		sb.append("<spbill_create_ip><![CDATA[").append(this.spbill_create_ip).append("]]></spbill_create_ip>");
		sb.append("<total_fee><![CDATA[").append(this.total_fee).append("]]></total_fee>");
		sb.append("<trade_type><![CDATA[").append(this.trade_type).append("]]></trade_type>");
		sb.append("<sign><![CDATA[").append(this.sign).append("]]></sign>");
		sb.append("</xml>");
		return sb.toString();
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}

	public void setTotal_fee(String total_fee) {
		this.total_fee = total_fee;
	}

	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}

	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}
}
